/**
 * 
 */
package com.wsd.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.wsd.bean.Articles;
import com.wsd.bean.Link;
import com.wsd.dao.LinkDaoInterface;

/**
 * @author Administrator
 *
 */
public class LinkDao extends HibernateDaoSupport implements LinkDaoInterface {

	/* (non-Javadoc)
	 * @see com.wsd.dao.LinkDaoInterface#delete(com.wsd.bean.Link)
	 */
	public void delete(Link persistentInstance) {
		try {
			getHibernateTemplate().delete(persistentInstance);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.wsd.dao.LinkDaoInterface#deleteById(int)
	 */
	public void deleteById(int id) {
		String sql = "delete Link where id = :id";
		Query query = getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery(sql);
		query.setInteger("id", id);
		query.executeUpdate();
	}

	/* (non-Javadoc)
	 * @see com.wsd.dao.LinkDaoInterface#findAll()
	 */
	public List<Link> findAll() {
		try {
			String queryString = "from Link";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.wsd.dao.LinkDaoInterface#findAll(int, int)
	 */
	public List<Link> findAll(int start, int limit) {
		String sql = "from Link order by id desc";
		Query query = getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery(sql);
		query.setMaxResults(limit);
		query.setFirstResult(start);
		return query.list();
	}

	/* (non-Javadoc)
	 * @see com.wsd.dao.LinkDaoInterface#findAllCount()
	 */
	public int findAllCount() {
		String sql = "select count(*) from Link";
		Query query = getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery(sql);
		Long count = (Long) query.uniqueResult();
		return count.intValue();
	}

	/* (non-Javadoc)
	 * @see com.wsd.dao.LinkDaoInterface#findById(java.lang.Integer)
	 */
	public Link findById(Integer id) {
		try {
			Link instance = (Link) getHibernateTemplate().get(
					"com.wsd.bean.Link", id);
			return instance;
		} catch (RuntimeException re) {
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.wsd.dao.LinkDaoInterface#findOnePage(int, int)
	 */
	public List<Link> findOnePage(int start, int pagesize) {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see com.wsd.dao.LinkDaoInterface#getTotallines()
	 */
	public List getTotallines() {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see com.wsd.dao.LinkDaoInterface#save(com.wsd.bean.Link)
	 */
	public void save(Link transientInstance) {
		try {
			getHibernateTemplate().save(transientInstance);
		} catch (RuntimeException re) {
			throw re;
		}
		
	}

	/* (non-Javadoc)
	 * @see com.wsd.dao.LinkDaoInterface#update(com.wsd.bean.Link)
	 */
	public void update(Link link) {
		getHibernateTemplate().update(link);
	}

}
